package cn.orange.ch10_dynamicprogramming;

import java.util.Arrays;

/**
 * LC300.最长递增子序列
 */
public class LC300 {
    public int lengthOfLIS(int[] nums) {
        int n = nums.length;
        //dp[i]:数组nums中以下标i为结尾(包括i)的子数组,最长递增子序列长度为dp[i]
        int[] dp = new int[n];
        Arrays.fill(dp, 1);
        int max = dp[0];
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                if (nums[i] > nums[j]) {
                    dp[i] = Math.max(dp[i], 1 + dp[j]);
                }
            }
            max = Math.max(max, dp[i]);
        }
        return max;
    }

    public static void main(String[] args) {
        LC300 alg = new LC300();
        System.out.println(alg.lengthOfLIS(new int[]{10, 9, 2, 5, 3, 7, 101, 18}));
        System.out.println(alg.lengthOfLIS(new int[]{0, 1, 0, 3, 2, 3}));
        System.out.println(alg.lengthOfLIS(new int[]{1, 3, 6, 7, 9, 4, 10, 5, 6}));
    }
}
